package CreationTools;

import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.MouseEvent;
import org.jhotdraw.figures.FigureAttributes;
import org.jhotdraw.framework.DrawingEditor;
import org.jhotdraw.framework.Figure;
import org.jhotdraw.framework.FigureAttributeConstant;
import org.jhotdraw.standard.CreationTool;

import FloorComponents.Grid;
import FloorComponents.Proxy;
import FloorComponents.Wall;

public class WallTool extends CreationTool {

	private Proxy _proxy;
	private Grid _grid;
	
	public WallTool(DrawingEditor newDrawingEditor, Figure prototype, Proxy grid) {
		super(newDrawingEditor, prototype);
		_proxy = grid;
		_grid = _proxy.get();
	}

	protected WallTool(DrawingEditor newDrawingEditor) {
		super(newDrawingEditor);
	}

	public void mouseDrag(MouseEvent e, int x, int y) {
		
		
		if (getAddedFigure() != null) {
			
			if (Math.abs(getAnchorX()-x)<Math.abs(getAnchorY()-y)){
				
				getAddedFigure().displayBox(new Point(getAnchorX(), getAnchorY()), new Point(getAnchorX()+10, y));
				
				
				if (y > getAnchorY()){
					for (int i = getAnchorX(); i <= getAnchorX()+10; i++)
						for (int j = getAnchorY(); j <= y; j++)
							_grid.add(i, j);
				}
				
				
				else {
					for (int i = getAnchorX(); i <= getAnchorX()+10; i++)
						for (int j = getAnchorY(); j >= y; j--)
							_grid.add(i, j);
				}
			}
			
			
			else{
				getAddedFigure().displayBox(new Point(getAnchorX(), getAnchorY()), new Point(x, getAnchorY()+10));
				if (x > getAnchorX()){
					for (int i = getAnchorX(); i <= x; i++)
						for (int j = getAnchorY(); j <= getAnchorX()+10; j++)
							_grid.add(i, j);
				}
				
				
				else {
					for (int i = getAnchorX(); i >= x; i--)
						for (int j = getAnchorY(); j <=getAnchorY(); j++)
							_grid.add(i, j);
				}
			}
		}
		_proxy.update(_grid);
	}
}